/*
 * Copyright © 2022-now 尛飛俠（Denvie） All rights reserved.
 */

package cn.denvie.springcloud.seata.order.controller;

import cn.denvie.springcloud.seata.common.model.entity.Order;
import cn.denvie.springcloud.seata.common.model.vo.ResultVo;
import cn.denvie.springcloud.seata.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Order控制器。
 *
 * @author Denvie
 * @date 2022/4/08
 * @since 1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 用户下单预订。
     * http://localhost:8620/order/booking?userId=ACCOUNT10000&commodityCode=PRODUCT10000&count=2&money=22
     */
    @RequestMapping("/booking")
    public ResultVo<Order> booking(String userId, String commodityCode, int count, int money) {
        log.info("收到预订请求，用户ID：{}, 商品编号：{}", userId, commodityCode);
        Order order = orderService.booking(userId, commodityCode, count, money);
        return ResultVo.ok(order);
    }

    /**
     * 用户下单采购。
     * http://localhost:8620/order/purchase?userId=ACCOUNT10000&commodityCode=PRODUCT10000&count=5&money=55
     */
    @RequestMapping("/purchase")
    public ResultVo<Order> purchase(String userId, String commodityCode, int count, int money) {
        log.info("收到采购请求，用户ID：{}, 商品编号：{}", userId, commodityCode);
        Order order = orderService.purchase(userId, commodityCode, count, money);
        return ResultVo.ok(order);
    }
}
